package com.whmnx.my.ui.viewmodel;

import android.app.Application;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableList;

import com.whmnx.base.constants.Constants;
import com.whmnx.base.utils.ImageUtil;
import com.whmnx.my.BR;
import com.whmnx.my.R;
import com.whmnx.my.databinding.FragmentTeamBinding;
import com.whmnx.my.ui.adapter.ViewPagerBindingAdapter3;
import com.whmnx.my.ui.fragment.AboutFragment2;
import com.whmnx.my.ui.fragment.MyTeamFragment;

import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.binding.command.BindingConsumer;
import me.goldze.mvvmhabit.utils.SPUtils;
import me.tatarka.bindingcollectionadapter2.BindingViewPagerAdapter;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

/**
 * author : huang
 * date   : 2020/9/18 0018 19:18
 * version: 1.0
 */
public class TeamModel extends ToolbarViewModel{
    //给ViewPager添加ObservableList
    public ObservableList<ViewPagerItemViewModel2> items = new ObservableArrayList<>();

    //给ViewPager添加ItemBinding
    public ItemBinding<ViewPagerItemViewModel2> itemBinding = ItemBinding.of(BR.viewModel, R.layout.item_team_viewpager);


    private String[] titles = new String[]{"直邀","间邀"};
    FragmentTeamBinding mBinding;
    MyTeamFragment mFragment;



    public TeamModel(@NonNull Application application) {
        super(application);
    }

    public void initToolbar(MyTeamFragment myTeamFragment, FragmentTeamBinding binding) {
        this.mBinding = binding;
        this.mFragment = myTeamFragment;
        setTitleText("我的团队");
        setRightText("规则说明");
        setRightTextVisible(View.VISIBLE);
        ImageUtil.setImage(mBinding.cIV, SPUtils.getInstance().getString(Constants.HEAD_IMG));
        mBinding.tv.setText(SPUtils.getInstance().getString(Constants.NICKNAME));
    }





    /**
     * 右边文字的点击事件，子类可重写
     */
    @Override
    public void rightTextOnClick() {
        Bundle bundle = new Bundle();
        bundle.putInt("code",2);
        startActivity(AboutFragment2.class,bundle);
    }


    public void addPage() {
        items.clear();
        //模拟3个ViewPager页面
        for (int i = 1; i <= titles.length; i++) {
            ViewPagerItemViewModel2 itemViewModel = new ViewPagerItemViewModel2(this, i);
            items.add(itemViewModel);
        }
    }


    //给ViewPager添加PageTitle
    public final BindingViewPagerAdapter.PageTitles<ViewPagerItemViewModel2> pageTitles = new BindingViewPagerAdapter.PageTitles<ViewPagerItemViewModel2>() {
        @Override
        public CharSequence getPageTitle(int position, ViewPagerItemViewModel2 item) {
            return titles[position];
        }
    };
    //给ViewPager添加Adpter，请使用自定义的Adapter继承BindingViewPagerAdapter，重写onBindBinding方法
    public final ViewPagerBindingAdapter3 adapter = new ViewPagerBindingAdapter3();

    //ViewPager切换监听
    public BindingCommand<Integer> onPageSelectedCommand = new BindingCommand<>(new BindingConsumer<Integer>() {
        @Override
        public void call(Integer index) {

        }
    });
}
